package jasonllinux.app.test;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Activity01 extends Activity {
  //Intent
	
	
	private TextView myTextView;
	private Button myButton;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		 
		super.onCreate(savedInstanceState);
		 setContentView(R.layout.main);

		 myTextView = (TextView)findViewById(R.id.mytext);
		 myButton = (Button)findViewById(R.id.mybutton);
		 myTextView.setText(R.string.hello);
		 myButton.setText(R.string.button);
		 myButton.setOnClickListener(new MyButtonListener());
//		myButton.setOnClickListener(new MyButtonListener1());
		 
	
	}
	
	class MyButtonListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			 Intent intent = new Intent();
			 intent.setClass(Activity01.this, Activity02.class);
			 Activity01.this.startActivity(intent);
			
		}	
	}
	
	class MyButtonListener1 implements OnClickListener{
		//Intent在不同应用程序之间传递
		@Override
		public void onClick(View v) {
			Uri uri = Uri.parse("smsto://15850775699");
			Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
			intent.putExtra("sms_body", "The text body we defined");
			Activity01.this.startActivity(intent);
			
		}
		
	}
	
	//menu不需要布局和配置
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		menu.add(0, 1, 1, R.string.exit);
		menu.add(0, 2, 2, R.string.about);
		return super.onCreateOptionsMenu(menu);
		
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == 1) {
			finish();
		}else if(item.getItemId() == 2) {
			
		}
		return super.onOptionsItemSelected(item);
	}
    
}